﻿using System;
using System.Collections.Generic;
using System.Runtime;
using System.Text;
using System.Threading.Tasks;

namespace Commons
{
    public static class StringExtensionMethod
    {
        public static int ToInt(this string str)
        {
            Task.Run((delegate {  }));
            return int.Parse(str);
        }

        public static Tout Trans<Tout, Tin>(this Tin tin)
        {
            Tout tOut = Activator.CreateInstance<Tout>();
            foreach (var itemOutInfo in tOut.GetType().GetProperties())
            {
                var propin = tin.GetType().GetType().GetProperty(itemOutInfo.Name);
                itemOutInfo.SetValue(tOut,propin.GetValue(tin));
            }
            foreach (var itemOut in tOut.GetType().GetFields())
            {
                var fieldIn = tin.GetType().GetField(itemOut.Name);
                itemOut.SetValue(tOut, fieldIn.GetValue(tin));
            }
            return tOut;
        }
    }
}
